<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同信息">
              <j-search-select-tag placeholder="请选择合同信息" v-model="queryParam.leaseContractId"
                                   :async="true"    dict="zcgl_lease_contract_info,contract_num,id" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="资产信息">
              <j-search-select-tag placeholder="请选择资产信息" v-model="queryParam.assetId"
                                   :async="true"      dict="zcgl_asset_info,asset_name,id" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="管理人员">
              <j-search-select-tag placeholder="请选管理人员" :async="true" v-model="queryParam.managerId"
                                   dict="sys_user,realname,id" />
            </a-form-item>
          </a-col>
          <a-col v-show="false" :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="付款状态">
              <a-input placeholder="请选择付款状态" v-model="queryParam.payStatus" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="管区">
                <j-dict-select-tag placeholder="请选管区" :async="true" v-model="queryParam.regional"
                                   dictCode="zcgl_regional" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户信息">
                <j-search-select-tag placeholder="请选择客户信息" v-model="queryParam.customerId"
                                     dict="zcgl_customer_info,name,id" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="付款金额">
                <a-input placeholder="请输入付款金额" v-model="queryParam.totalMoney"></a-input>
              </a-form-item>
            </a-col>
            <!--<a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="付款状态">
                <j-dict-select-tag placeholder="请选择付款状态" v-model="queryParam.payStatus" dictCode="payment_status"/>
              </a-form-item>
            </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="付款方式">
                <j-dict-select-tag placeholder="请选择付款方式" v-model="queryParam.paymentType" dictCode="pay_type" />
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="付款日期">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.paymentDate_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.paymentDate_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="付款人">
                <j-search-select-tag placeholder="请选择付款人" v-model="queryParam.paymentBy" dict="sys_user,realname,id" />
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-is-group>
              <a-form-item label="所属公司">
                <j-company-select-tag placeholder="请选择所属公司" v-model="queryParam.companyId" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'payableInfoUn:add'" @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button v-has="'payableInfoUn:export'" type="primary" icon="download" @click="handleExportXls('应付款项')">导出
      </a-button>
      <a-upload v-has="'payableInfoUn:import'" name="file" :showUploadList="false" :multiple="false"
                :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button v-has="'payableInfoUn:temp'" type="primary" icon="download" @click="handleExportXlsTemplate('应付款项模板')">
        模板下载
      </a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item v-has="'payableInfoUn:delete'" key="1" @click="batchDel">
            <a-icon type="delete" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange , getCheckboxProps: getCheckboxProps}"
        :scroll="{ x: 2000, y: screenHeight}"
        class="j-table-force-wrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">


          <a v-has="'payableInfoUn:look'" @click="handleDetail(record)">查看</a>

          <span v-if="record.payStatus == 10 || record.payStatus == null">

            <a-divider v-has="'payableInfoUn:payment'" type="vertical" />
            <a v-has="'payableInfoUn:payment'" @click="handleOperation('付款', record, 1)">付款</a>

            <a-divider type="vertical" />
            <a-dropdown>
              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
              <a-menu slot="overlay">
                <a-menu-item v-has="'payableInfoUn:edit'">
                  <a @click="handleEdit(record)">编辑</a>
                </a-menu-item>
                <a-menu-item v-has="'payableInfoUn:delete'">
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </span>
        </span>

      </a-table>
    </div>

    <payablesInfo-modal ref="modalForm" @ok="modalFormOk"></payablesInfo-modal>
    <payablesInfoOperation-modal ref="modalOperationForm" @ok="modalOperationOk"></payablesInfoOperation-modal>
    <!--流程表单-->
    <a-modal :title="lcModa.title" v-model="lcModa.visible" :footer="null" :maskClosable="false" width="80%">
      <component :disabled="lcModa.disabled" v-if="lcModa.visible" :is="lcModa.formComponent"
                 :processData="lcModa.processData" :isNew="lcModa.isNew"
                 @afterSubmit="processFormOk" @close="lcModa.visible=false, lcModa.disabled = false"></component>
    </a-modal>
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import PayablesInfoModal from './modules/PayablesInfoModal'
import PayablesInfoOperationModal from './modules/PayablesInfoOperationModal'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import JDate from '@/components/jeecg/JDate.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import '@/assets/less/TableExpand.less'
import { buildTableMethod, buildTableData } from '@/api/payablesInfoData'
import { activitiMixin } from '@views/activiti/mixins/activitiMixin'
import { mixinDevice } from '@/utils/mixin'
import JCompanySelectTag from '@comp/jeecg/JCompanySelectTag'

export default {
  name: 'PayablesInfoList',
  mixins: [activitiMixin, JeecgListMixin, mixinDevice],
  components: {
    JDictSelectTag,
    JDate,
    JSearchSelectTag,
    JCompanySelectTag,
    PayablesInfoOperationModal,
    PayablesInfoModal
  },
  data () {
    return buildTableData({
      description: '应付款项管理页面',
      queryParam: {
        payStatus: 10
      }
    })
    // return {
    //
    // }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: buildTableMethod({
    initDictConfig () {
      this.columns[0].customRender = (text, record, index) => `${(this.ipagination.current - 1) * this.ipagination.pageSize + index + 1}`
      this.addColumns()
    },
    getCheckboxProps: record => ({
      props: {
        // 全部默认禁止选中
        // disabled: true,
        // 某几项默认禁止选中(R: 当state等于1时)
        disabled: record.processStatus == 2 || record.processStatus == 1
      }
    }),
    //自己的方法
    searchReset () {
      this.queryParam = { payStatus: 10 }
      this.loadData(1)
    },
    paymentForm (r) {
      let tableData = {
        routeName: '@/views/activiti/form/PaymentForm',
        tableName: 'zcgl_payables_info',
        tableId: r.id
      }
      this.processCreateCom(tableData, '发起退款付款申请流程', r.processStatus)
    }
  })
  // methods: {
  //
  // }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>